
import VueRouter from "vue-router";
import LoginVue from "@/views/LoginVue.vue";
import LayoutVue from "@/views/LayoutVue.vue";
import StudentVue from "@/views/StudentVue.vue";
import TeacherVue from "@/views/TeacherVue .vue";
import CourseVue from "@/views/CourseVue.vue"
import EditPwd from "@/views/EditPwd.vue"
import SpersonMsg from "@/views/SpersonMsg.vue"
import TpersonMsg from "@/views/TpersonMsg.vue"
import IndexVue from "@/views/IndexVue.vue"
import ClassVue from "@/views/ClassVue.vue"
import ShareVue from "@/views/ShareVue.vue"
import CourseMsg from "@/views/CourseMsg.vue"
import StuCourse from "@/views/StuCourse.vue"
import TeaCourse from "@/views/TeaCourse.vue"
import WorkSubmit from "@/views/WorkSubmit.vue"
import LookWork from "@/views/LookWork.vue"
import GradeVue from "@/views/GradeVue.vue"
import ReviewWork from "@/views/ReviewWork.vue"

import Vue from "vue";
import { Message } from 'element-ui';

Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    name: 'LoginVue',
    meta: { title: '登录' },
    component: LoginVue
  },
  {
    path: '/',
    name: 'LayoutVue',
    meta: { title: '父' },
    redirect: '/index',
    component: LayoutVue,
    //子路由
    children: [
      { path: '/index', name: 'IndexVue', meta: { title: '首页' }, component: IndexVue },
      { path: '/student', name: 'StudentVue', meta: { title: '学生信息' }, component: StudentVue },
      { path: '/teacher', name: 'TeacherVue', meta: { title: '教师信息' }, component: TeacherVue },
      { path: '/class', name: 'ClassVue', meta: { title: '班级信息' }, component: ClassVue },
      { path: '/course', name: 'CourseVue', meta: { title: '课程信息' }, component: CourseVue },
      { path: '/sharecourse', name: 'ShareVue', meta: { title: '课程分配记录' }, component: ShareVue },
      { path: '/SpersonMsg', name: 'SpersonMsg', meta: { title: '学生个人信息' }, component: SpersonMsg },
      { path: '/TpersonMsg', name: 'TpersonMsg', meta: { title: '教师个人信息' }, component: TpersonMsg },
      { path: '/EditPwd', name: 'EditPwd ', meta: { title: '修改密码' }, component: EditPwd },
      { path: '/StuCourse:courseName:courseId:teaName:classId', name: 'StuCourse ', meta: { title: '学生具体课程信息' }, component: StuCourse },
      { path: '/TeaCourse:courseName:courseId:classId', name: 'TeaCourse ', meta: { title: '教师具体课程信息' }, component: TeaCourse },
      { path: '/WorkSubmit:homeworkId', name: 'WorkSubmit ', meta: { title: '作业提交页面' }, component: WorkSubmit },
      { path: '/LookWork:homeworkId:classId', name: 'LookWork', meta: { title: '作业查看页面' }, component: LookWork },
      { path: '/ReviewWork:homeworkId:stuId', name: 'ReviewWork', meta: { title: '作业批改页面' }, component: ReviewWork },
      { path: '/GradeVue', name: 'GradeVue', meta: { title: '学生课程成绩页面' }, component: GradeVue },

      //课程信息
      {
        path: '/CourseMsg',
        name: 'CourseMsg ',
        meta: { title: '课程信息' },
        component: CourseMsg,
        //课程信息子路由
        children:[

        ]
      
      }

      // { path: '/EditPwd',name: 'EditPwd ',meta: { title: '我的课程' },  component: EditPwd },

    ]
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})


//router全局前置守卫
router.beforeEach((to, from, next) => {
  // 判断该路由是否需要登录权限
  if (to.path === "/login") {
    next()
  } else {
    if (localStorage.getItem("user")) {
      next();
    } else {
      next('/login')
      Message.error("请先登录")
    }

  }
})



export default router




